<template>
	<view>
		<view class="zy-col list-item">
			<view class="zy-row item-details">
				<text class="item-title" style="font-weight: 800;color: #000;font-size: 38rpx;">网鞋鞋面</text>
			</view>
			<view class="zy-row item-details">
				<text class="item-title">订单编号：</text>
				<text>teiwu439834802832u49</text>
			</view>
			<view class="zy-row item-details">
				<text class="item-title">服务类型：</text>
				<text>清洗-网面球鞋</text>
			</view>
			<view class="zy-row item-details">
				<text class="item-title">数量：</text>
				<text>20</text>
			</view>
			<view class="zy-row list-item-img-text">
				*单只鞋图片上传不少于3张
			</view>
			<u-upload  uploadText="上传图片" accept="image " 
			:fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="10">
			</u-upload>
			
			<view class="zy-row" style="justify-content: center;margin-top: 160rpx;">
				<view v-if="fileList1.length>3" class="btn-activate">
					确认提交
				</view>
				<view v-else class="btn-activate" style="background: #C3C3C3;">
					确认提交
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList1: [],
			};
		},
		onLoad() {},
		methods: {
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style lang="scss">
	.on-back {
		width: 100%;
		height: 62rpx;
		position: absolute;
		z-index: 1;
		right: 0rpx;
		align-items: center;
		padding-left: 36rpx;
		top: calc(55rpx + var(--status-bar-height));

		.title {
			font-size: 32rpx;
			font-weight: 500;
			color: #FFFFFF;
			margin-left: 230rpx;
		}
	}

	.uni-margin-wrap {
		position: relative;
		width: 100%;
		height: 750rpx;

		swiper {
			width: 100%;
			height: 750rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.img-details {
			position: absolute;
			z-index: 5;
			bottom: 20rpx;
			right: 28rpx;
			width: 98rpx;
			height: 62rpx;
			background: #000000;
			border-radius: 38rpx;
			opacity: 0.38;
		}

		text {
			position: absolute;
			z-index: 100;
			bottom: 32rpx;
			right: 52rpx;
			font-size: 28rpx;
			color: #fff;
		}
	}

	.list-item {
		background-color: #fff;
		padding: 20rpx 28rpx;

		&-img-text{
			font-size: 20rpx;
			color: #FF2A44;
			margin-top: 16rpx;
			margin-bottom: 24rpx;
		}
	
		.item-details {
			text {
				font-size: 28rpx;
			}

			.item-title {
				text-align: right;
				color: #333333;
			}

			&:nth-child(n+2) {
				margin-top: 20rpx;
			}

			.item-right {
				flex-wrap: wrap;
				width: 620rpx;

				text {
					height: 42rpx;
					line-height: 42rpx;

					&:nth-child(n+2) {
						margin-left: 20rpx;
					}

					&:nth-child(3n+1) {
						margin-left: 0rpx;
					}
				}
			}
		}

	}
</style>
